package com.qiji.video.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiji.video.bean.Admins;
import com.qiji.video.bean.TypeVideo;
import com.qiji.video.bean.Videos;
import com.qiji.video.bean.extend.FuzzyQuery_Video;
import com.qiji.video.mapper.TypeVideoMapper;
import com.qiji.video.mapper.VideoTypeMapper;
import com.qiji.video.mapper.VideosMapper;
import com.qiji.video.mapper.extend.VideosExtendMapper;
import com.qiji.video.service.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
public class VideoServiceImpl implements IVideoService {

    @Autowired
    private VideosMapper videosMapper;

    @Autowired
    private VideosExtendMapper videosExtendMapper;

    @Autowired
    private TypeVideoMapper typeVideoMapper;

    @Autowired
    private VideoTypeMapper videoTypeMapper;

    @Override
    public void addVideos(Videos videos) {
        videosMapper.insert(videos);
    }

    @Override
    public void uploadVideos(MultipartFile multipartFile) {


    }

    @Override
    public void downloadVideos(MultipartFile file) {

    }

    @Override
    public List<String> selectVideoType(Integer id) {
        return typeVideoMapper.selectByVid(id);
    }

    @Override
    public void insertVideoType(Integer vid,List<String> VType) {
//        System.out.println(vid);
//        System.out.println(VType);
        TypeVideo typeVideo = new TypeVideo();
        typeVideo.setId(null);
        typeVideo.setVid(vid);
        int dd;
//        System.out.println(1);
//        System.out.println(VType.get(0));
        for(int i=0;i<VType.size();i++){
            dd=videoTypeMapper.selectByType(VType.get(i));
//            System.out.println(dd);
            typeVideo.setTypeId(dd);
            typeVideoMapper.insert(typeVideo);
        }
    }

    @Override
    public void deleteVideoType(Integer vid) {
        videoTypeMapper.deleteByVid(vid);
    }

    @Override
    public int getLastID() {
        return videosMapper.selectLastId();
    }

    @Override
    public void deleteVides(int id) {
        videosMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateVideos(Videos videos) {
        videosMapper.updateByPrimaryKey(videos);
    }

    @Override
    public PageInfo<Videos> pageQueryfuzzyEnquiryVideos(int pageNum, int pageSize, FuzzyQuery_Video fuzzyQuery_video) {
        PageHelper.startPage(pageNum, pageSize);
        List<Videos> list=videosExtendMapper.fuzzyEnquiryVideos(fuzzyQuery_video);
        return new PageInfo(list);
    }

    @Override
    public Videos selectVideosDetail(int id) {
        return videosMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Videos> pageInfoByName(int pageNum, int pageSize,String name){

        PageHelper.startPage(pageNum,pageSize);
        List<Videos> videos = videosExtendMapper.selectListByName(name);
        return new PageInfo<>(videos);

    }
    @Override
    public List<Videos> hotsearch(){

        return  videosExtendMapper.hotsearch();

    }


    @Override
    public  List<Videos> selectPartitioningById(Integer id){
        return videosExtendMapper.selectPartitioningByid(id);
    }


}
